package HOANGTHANHCONG_SWING_BAI4;

import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Vieww {

	private JFrame frmChnL;
	private JTextField txtGtri;
	private JTextField txtKq;
	controller ctrl1 = new controller();
	mODEL model1 = new mODEL();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Vieww window = new Vieww();
					window.frmChnL.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Vieww() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmChnL = new JFrame();
		frmChnL.getContentPane().setVisible(false);
		frmChnL.setTitle("Chẵn lẻ");
		frmChnL.setIconImage(Toolkit.getDefaultToolkit().getImage(Vieww.class.getResource("/HOANGTHANHCONG_SWING_Bai1/search_icon.gif")));
		frmChnL.setBounds(100, 100, 450, 300);
		frmChnL.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmChnL.getContentPane().setLayout(null);
		
		
		JLabel lblNewLabel = new JLabel("Nhập giá trị dãy số:");
		lblNewLabel.setBounds(10, 28, 104, 14);
		frmChnL.getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Chọn kiểu giá trị:");
		lblNewLabel_1.setBounds(10, 81, 104, 14);
		frmChnL.getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Kết quả: ");
		lblNewLabel_2.setBounds(10, 141, 46, 14);
		frmChnL.getContentPane().add(lblNewLabel_2);
		
		
		
		txtGtri = new JTextField();
		txtGtri.setBounds(146, 25, 226, 20);
		frmChnL.getContentPane().add(txtGtri);
		txtGtri.setColumns(10);
		
		txtKq = new JTextField();
		txtKq.setBounds(10, 166, 414, 85);
		frmChnL.getContentPane().add(txtKq);
		txtKq.setColumns(10);
		
		final JComboBox cbbKGT = new JComboBox();
		cbbKGT.setModel(new DefaultComboBoxModel(new String[] {"", "Chẵn", "Lẻ"}));
		cbbKGT.setBounds(146, 78, 226, 20);
		frmChnL.getContentPane().add(cbbKGT);
		JButton btnNewButton = new JButton("Xem");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (txtGtri.getText().isEmpty()){txtKq.setText("Chưa nhập giá trị dãy số!");}
				model1.setA(Integer.parseInt(txtGtri.getText()));
				if(cbbKGT.getSelectedIndex()==2){
					for(int i = 1;i<model1.getA();i++){
						if (i%2==1) txtKq.setText(" "+i);
						}}
				else if(cbbKGT.getSelectedIndex()==1){ctrl1.xulichan(model1);}
				else {txtKq.setText("Chưa chọn kiểu giá trị");}
			}
		});
		btnNewButton.setBounds(217, 121, 89, 23);
		frmChnL.getContentPane().add(btnNewButton);
	}

}
